package util;

import java.io.InputStream;
import java.net.*;
import java.util.List;

/**
 * Created by ldh on 2018/12/5.
 */
public class FetchCookie {

    public static void main(String args[]) throws Exception {
        String urlString = "https://www.baidu.com";
        CookieManager manager = new CookieManager();
//        HttpCookie loginCookie = new HttpCookie()
//        manager.getCookieStore().add("https://abs-in.idumiao.com", cookie);
        CookieHandler.setDefault(manager);
        URL url = new URL(urlString);
        URLConnection connection = url.openConnection();
        InputStream in = connection.getInputStream();
        int size = in.available();
        int t = 0;
        while(in.read() != -1) {

        }
        CookieStore cookieJar = manager.getCookieStore();
        List<HttpCookie> cookies = cookieJar.getCookies();
        for (HttpCookie cookie : cookies) {
            System.out.println(cookie.getName() + "," + cookie.getSecure());
        }
        in.close();
    }
}
